package com.xmwzw.catpu.viewmodel;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.text.TextUtils;

import com.xmwzw.catpu.validator.PhoneValidator;
import com.xmwzw.catpu.validator.RangeValidator;

/**
 * @author : wangzw
 * @date : 20-4-1下午7:32
 * @desc :
 */
public class LoginViewModel extends BaseObservable {
    private PhoneValidator phoneValidator = new PhoneValidator("");
    private RangeValidator passwordValidator = new RangeValidator("", 6, 20);

    @Bindable
    public String mAccount = "";

    @Bindable
    public String mPassword = "";

    @Bindable
    public boolean showLoadingDialog = false;

    public void setShowLoadingDialog(boolean showLoadingDialog) {
        this.showLoadingDialog = showLoadingDialog;
        notifyChange();
    }

    @Bindable
    public boolean isShowLoadingDialog() {
        return showLoadingDialog;
    }

    @Bindable
    public String getValidateError() {
        String error = "";
        if (TextUtils.isEmpty(mAccount) || !phoneValidator.isValid(mAccount)) {
            error = "请填写有效的手机号";
        } else if (TextUtils.isEmpty(mPassword) || !passwordValidator.isValid(mPassword)) {
            error = "请填写最少6位密码";
        }
        return error;
    }
}